/*
 * validateParameterInput.js
 * v 0.03
 * 3/15/2011
 */

 /* This function checks if the input is a valid integer or decimal number */
function validDecimal( input ) {
	var msg = input.value; 
    var w;
    var decimal = msg.indexOf( "." );
    var index;
  
    for ( w=0; w<msg.length; w++ )  {
		index = msg.substring(w,w+1);
		if ( index<"0" || index>"9" )  {
			if ( decimal>0 )
				if ( w==decimal )  continue;    
			msg = msg.substring(0,w);
			input.value = msg; 
			break;           
      }
	 }
}

function checkEmpty(id1,id2,id3){
	
	var i;
	var id;
	var errorid;
	var len = id1.length;
	var last = id1.charAt(len-1);
	var letter;
	var len2 = id2.length;
	var len3 = id3.length;
	var par1;
	var par2;
	var par3;
	
	switch (last) {
		case '1': letter = "a"; break;
		case '2': letter = "b"; break;
		case '3': letter = "c"; break;
	}

	if ((len-3)==0) { 
		par1 = id1.charAt(0);
	} else {
		par1 = id1.charAt(0) + id1.charAt(1);
	}
	if ((len2-3)==0) { 
		par2 = id2.charAt(0);
	} else {
		par2 = id2.charAt(0) + id2.charAt(1);
	}
	if ((len3-3)==0) { 
		par3 = id3.charAt(0);
	} else {
		par3 = id3.charAt(0) + id3.charAt(1);
	}
	/* Requires input to be greater than 0 */
	if (par1 == 8) {
		if (parseFloat(document.getElementById(id1).value)==0) {
			document.getElementById("error1" + letter).innerHTML = "Enter number greater than 0";
			return false;
		}
	}
	if (par2 == 15 || par2 == 12 || par2 == 2) {
		if (parseFloat(document.getElementById(id2).value)==0) {
			document.getElementById("error2" + letter).innerHTML = "Enter number greater than 0";
			return false;
		}
	}
	if (par3 == 6) {
		if (parseFloat(document.getElementById(id3).value)==0) {
			document.getElementById("error3" + letter).innerHTML = "Enter number greater than 0";
			return false;
		}
	}
	/* Checks if the fields are empty */
	if(document.getElementById(id1).value == "" || document.getElementById(id2).value == ""
			|| document.getElementById(id3).value == "" ){
			for(i=0; i<3; i++){
				switch(i){
					case 0: id = id1; errorid = "error1" +  letter; break;
					case 1: id = id2; errorid = "error2" +  letter;  break;
					case 2: id = id3; errorid = "error3" +  letter;  break;
				}
					if  (document.getElementById(id).value == ""){
						document.getElementById(errorid).innerHTML = "Required field";
					}else{
						document.getElementById(errorid).innerHTML = "";
					}
			}
			return false;
		}else{
			return true;
		}

}

function checkEmptyCarb(id1,id2,id3,id4,id5){
	
	var i;
	var id;
	var errorid;
	var len = id1.length;
	var last = id1.charAt(len-1);
	var letter;

	if(document.getElementById(id1).value == "" || 
			document.getElementById(id2).value == "" || 
			document.getElementById(id3).value == "" || 
			document.getElementById(id4).value == "" ||
			document.getElementById(id5).value == ""){
			
		switch (last) {
			case '1': letter = "a"; break;
			case '2': letter = "b"; break;
			case '3': letter = "c"; break;
		}
		for(i=0; i<5; i++){
			switch(i){
				case 0: id = id1; errorid = "error1" +  letter; break;
				case 1: id = id2; errorid = "error2" +  letter;  break;
				case 2: id = id3; errorid = "error3" +  letter;  break;
				case 3: id = id3; errorid = "error4" +  letter;  break;
				case 4: id = id3; errorid = "error5" +  letter;  break;
			}
			if  (document.getElementById(id).value == ""){
				document.getElementById(errorid).innerHTML = "Required field";
			}else{
				document.getElementById(errorid).innerHTML = "";
			}
		}
		return false;
	}else{
		return true;
	}
}

function enable(input, id){
	if (input.id == "c1") {
		if (document.getElementById(id+'/1').disabled == false) {
			document.getElementById(id+'/1').disabled = true;
		} else{
			document.getElementById(id+'/1').disabled = false;
		}
	}
	if (input.id == "c2") {
		if (document.getElementById(id+'/2').disabled == false) {
			document.getElementById(id+'/2').disabled = true;
		} else{
			document.getElementById(id+'/2').disabled = false;
		}
	}
	if (input.id == "c3") {
		if (document.getElementById(id+'/3').disabled == false) {
			document.getElementById(id+'/3').disabled = true;
		} else{
			document.getElementById(id+'/3').disabled = false;
		}
	}		
}